<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<%@include file="/common/head.jsp" %>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form role="form" class="form-inline" id="query-form" method="post"
                          action="${ctx }/admin/customer/accountManageList">
                        <!-- 查询开始 -->
                        <div class="form-group">
                            <input type="text" id="query-name" name="nameOrMobile" value="${query.nameOrMobile}"
                                   class="form-control input-sm" placeholder="输入医生名称/联系方式">

                        </div>
                        <div class="form-group">
                            <select name="agentId" id="query-agent" class="form-control">
                                <option value="">选择代理商</option>
                                <c:forEach items="${agentList}" var="a">
                                    <option value="${a.id}" <c:if test="${query.agent.id == a.id}">selected</c:if>>${a.orgName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="query-status" class="sr-only2">状态</label>
                            <select name="status" id="query-status" value="${query.status}" class="form-control">
                                <option value="">全部</option>
                                <option value="0" <c:if test="${query.status == 0}">selected</c:if>>已禁用</option>
                                <option value="1" <c:if test="${query.status == 1}">selected</c:if>>已启用</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="query-status" class="sr-only2">注册时间：</label>
                            <input type="text" class="form-control" name="startDate"
                                   value="${query.startDate}"
                                   onclick="laydate({format: 'YYYY-MM-DD'})" placeholder="开始时间" style="width: 100px">
                            至
                            <input type="text" class="form-control" name="endDate"
                                   value="${query.endDate}"
                                   onclick="laydate({format: 'YYYY-MM-DD'})" placeholder="结束时间" style="width: 100px">
                        </div>
                        <div class="form-group">
                            <button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-search"></i>&nbsp;查询
                            </button>
                        </div>
                        <!-- 查询结束 -->
                    </form>

                    <div>
                        <p>
                            <button type="button" class="btn btn-sm btn-outline btn-primary" onclick="output()">
                                导出
                            </button>
                        </p>
                    </div>
                    <table id="table" data-toggle="table" data-striped="true" data-click-to-select="true"
                           data-mobile-responsive="true">
                        <thead>
                        <tr>
                            <th data-field="id" data-visible="false">ID</th>
                            <th data-field="status">用户类型</th>
                            <th data-field="created">注册时间</th>
                            <th data-field="agent">所属代理商</th>
                            <th data-field="orgName">机构名称</th>
                            <th data-field="clientName">医生名称</th>
                            <th data-field="mobile">联系方式</th>
                            <th data-field="expireDate">到期时间</th>
                            <th data-field="residualTime">剩余时间</th>
                            <th data-field="operation">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${list }" var="n" varStatus="idx">
                            <tr data-index="${idx.index }" data-id="${n.id }">
                                <td style="">${n.id }</td>
                                <%--<td>${enum:list('CustomerStatus', n.status)}</td>--%>
                                <td style="">
                                    <c:forEach items="${types}" var="t">
                                        <c:if test="${n.type == t.value }">
                                            ${t.remark}
                                        </c:if>
                                    </c:forEach>
                                </td>
                                <td><fmt:formatDate value="${n.created}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                <td>${n.agent.orgName}</td>
                                <td style="">${n.orgName }</td>
                                <td style="">${n.name }</td>
                                <td style="">${n.mobile }</td>
                                <td style="">
                                    <c:choose>
                                        <c:when test="${n.expireDate == null }">
                                            <fmt:formatDate value="${n.created}" pattern="yyyy-MM-dd"/>
                                        </c:when>
                                        <c:otherwise>
                                            <c:if test="${n.restDays < 10 }">
                                                <b style="color: red;"><fmt:formatDate value="${n.expireDate}" pattern="yyyy-MM-dd"/></b>
                                            </c:if>
                                            <c:if test="${n.restDays >= 10}">
                                                <fmt:formatDate value="${n.expireDate}" pattern="yyyy-MM-dd"/>
                                            </c:if>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td style="">
                                    <c:choose>
                                        <c:when test="${n.expireDate == null }">
                                            <b style="color: red;">未激活</b>
                                        </c:when>
                                        <c:otherwise>
                                            <c:if test="${n.restDays < 10 && n.restDays >= 0}"><b style="color: red;">${n.restDays}天</b></c:if>
                                            <c:if test="${n.restDays >= 10}">${n.restDays}天</c:if>
                                            <c:if test="${n.restDays < 0}"><b style="color: red;">已到期</b></c:if>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td style="">
                                    <a href="javascript: void(0);" onclick="detail(${n.id})">详情</a>
                                    <c:if test="${n.status == 0}">
                                        <a href="javascript: void(0);" onclick="updateStatus(${n.id}, 1)">启用</a>&nbsp;&nbsp;
                                    </c:if>
                                    <c:if test="${n.status == 1}">
                                        <a href="javascript: void(0);" onclick="updateStatus(${n.id}, 0)">禁用</a>&nbsp;&nbsp;
                                    </c:if>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>

                    <%@include file="/common/page.jsp" %>
                </div>
            </div>
        </div>
    </div>
</div>

<%@include file="/common/foot.jsp" %>
<script>
    function detail(id) {
        k.layer.showDetail("${ctx}/admin/customer/accountManageDetail?id="+id);
    }

    function updateStatus(id, status) {
        k.layer.updateStatus('${ctx}/admin/customer/enableOrDisable', id, status);
    }

    function output() {
        var agentId = $("#query-agent").val();
        var status = $("#query-status").val();
        window.location.href="${ctx}/admin/reportForm/exportCustomer?agentId="+agentId+"&status="+status;
    }
    
    var page = "${page.page}";

    function reload() {
        page_submit(page);
    }
    paging('pagination', ${page.totalPages}, ${page.page});

</script>
</body>
</html>